package com.example.lin.generate;

import com.example.lin.util.DateUtils;
import com.example.lin.util.ExportUtil;
import com.example.lin.util.ImportUtil;
import org.junit.jupiter.api.Test;

import java.util.Date;
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * @author GuLin
 * @create 2025-05-30 16:38
 */
public class CooInfo {

    @Test
    public void generateSQLOutText() {
        String filePath = "C:\\Users\\181596\\Desktop\\COO 白名单第四批.xlsx";
        int sheet = 0;
        String template = "INSERT INTO `t_coo_manual_whitelist` (`id`, `coo_type`, `code_value`, `name_value`, `origin_country`, `destination_country`, `is_active`, `create_time`, `create_user_code`, `modify_time`, `modify_user_code`) " +
                "VALUES (%s, 'COO_SELLER_ID_CATEGORY', \"%s\", null, 'CN', 'US', 1, NOW(), '181596', NOW(), '181596');";
        List<List<Object>> list = ImportUtil.readExcelToList(filePath, sheet);
        //System.out.println(list);
        List<Object> sqlList = new LinkedList<>();
        AtomicInteger i = new AtomicInteger();
        list.forEach(e -> {
            int andIncrement = i.getAndIncrement();
            String id = DateUtils.format(new Date(), DateUtils.YMDHS_FORMAT) + String.format("%06d", andIncrement);
            String codeValue = String.valueOf(e.get(0)).replaceAll("\\s+", "").toUpperCase();
            //String nameValue = String.valueOf(e.get(1)).replaceAll("\\s+", "").toUpperCase();
            String format = String.format(template, id, codeValue);
            sqlList.add(format);
        });
        ExportUtil.writeDataToFile(sqlList, "国家代码CN" + sheet);
        System.out.println("完成");
    }

}
